const path = require('path');
// Glob 是一种用来匹配路径与文件的模式。
const glob = require('glob');
const cwd = process.cwd()

// const entries = getEntry('src/js/page/**/*.js', 'src/js/page/');
// var chunks = Object.keys(entries);
// console.log(entries);
// console.log(chunks);

// const pages = Object.keys(getEntry('src/view/**/*.html', 'src/view/'));
console.log(getEntry('src/view/**/*.html', 'src/view/'));
// pages.forEach((pathname)=>{
//     let conf = {
//         filename: 'view/' + pathname + '.html', //生成的html存放路径，相对于path
//         template: 'src/view/' + pathname + '.html', //html模板路径
//         inject: false
//     };
//     if(pathname in entries){
//         // conf.favicon = 'src/imgs/favicon.ico';
//         conf.inject = 'body';
//         conf.chunks = ['vendors', pathname];
//         conf.hash = true;
//     }
//     console.log(conf);
// });

function getEntry(globPath, pathDir) {
    var files = glob.sync(globPath);
    var entries = {},
        entry, dirname, basename, pathname, extname;
    const reg = /src\/(\S+).html$/

    for (var i = 0; i < files.length; i++) {
        const filename = files[i].match(reg)[1]
        console.log(filename)
        // entry = files[i];
        // dirname = path.dirname(entry);
        // extname = path.extname(entry);
        // // http://nodejs.cn/api/path.html#path_path_basename_path_ext
        // basename = path.basename(entry, extname);
        // pathname = path.join(dirname, basename);
        // pathname = pathDir ? pathname.replace(new RegExp('^' + pathDir), '') : pathname;
        // entries[basename] = ['./' + entry];
    }
    return entries;
}